﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CsvViewer
{
    public partial class DataImportForm : Form
    {
        List<string> headers = new List<string>();
        List<ColumnDataType> dts = new List<ColumnDataType>();


        public DataImportForm()
        {
            InitializeComponent();
        }

        public void SetData(CSV csv)
        {
            var headerNames = csv.GetRowAt(0);
            listBox1.Items.Clear();
            for (int i = 0; i < headerNames.Length; i++)
            {
                headers.Add(headerNames[i]);
                dts.Add(ColumnDataType.String);
                listBox1.Items.Add($"{i + 1}.{headers[i],-20}    {dts[i]}");
            }

            if(listBox1.Items.Count > 0)
                listBox1.SelectedIndex = 0;

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                cbDataType.Text = dts[listBox1.SelectedIndex].ToString();
            }
        }

        private void DataImportForm_Load(object sender, EventArgs e)
        {
            ColumnDataType[] dts =
            {
                ColumnDataType.String,
                ColumnDataType.DateTime,
                ColumnDataType.Integer,
                ColumnDataType.Float,
                ColumnDataType.Object
            };

            cbDataType.Items.Clear();
            foreach (ColumnDataType dt in dts)
                cbDataType.Items.Add(dt.ToString());
        }

        private void cbDataType_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = listBox1.SelectedIndex;
            if (i != -1)
            {
                dts[i] = (ColumnDataType)Enum.Parse(typeof(ColumnDataType), cbDataType.Text);
                // if (Enum.TryParse(colorName, out color))
                // dts[i] = (ColumnDataType)cbDataType.SelectedItem;
                listBox1.Items[i] = $"{i + 1}.{headers[i],-20}    {dts[i]}";
            }




        }

    }
}
